﻿<?xml version="1.0" encoding="utf-8" ?>

<cls:class
	name="CdDrive"
	type="http://metalx.org/Storage/CdDrive"
	xmlns="http://metalx.org/Program"
	xmlns:cls="http://metalx.org/Class"
	xmlns:var="http://metalx.org/Variable"
	xmlns:obj="http://metalx.org/i386/Functions/Object"
	xmlns:sys="http://metalx.org/i386/Functions/System"
	xmlns:cat="http://metalx.org/i386/Functions/Catalog"
	xmlns:str="http://metalx.org/i386/Functions/String"
	xmlns:int="http://metalx.org/i386/Functions/Integer"
	xmlns:bool="http://metalx.org/i386/Functions/Boolean"
	xmlns:lst="http://metalx.org/i386/Functions/List"
	xmlns:cd="http://metalx.org/i386/Functions/CdDrive"
	xmlns:hex="http://metalx.org/i386/Functions/Hexadecimal"
	xmlns:mm="http://metalx.org/i386/Functions/MemoryManager"
	xmlns:clsf="http://metalx.org/i386/Functions/Class"
	xmlns:pata="http://metalx.org/Pc/Pata/Ports"
	xmlns:status="http://metalx.org/Pc/Pata/Status"
	xmlns:drive="http://metalx.org/Pc/Pata/DriveSelect"
	xmlns:cmd="http://metalx.org/Pc/Pata/Commands"
	xmlns:cpu="http://metalx.org/Intel/80386/Operators"
	xmlns:op="http://metalx.org/Intel/80386/Operands"
	xmlns:imm="http://metalx.org/Intel/80386/Immediate"
	xmlns:math="http://metalx.org/Intel/80386/Math"
	xmlns:ari="http://metalx.org/Intel/80386/Arithmetic"
	xmlns:shift="http://metalx.org/Intel/80386/Shift"
	xmlns:logic="http://metalx.org/Intel/80386/Logic"
	xmlns:port="http://metalx.org/Pc/Ports"
	xmlns:pci="http://metalx.org/Pc/Pci/Ports"
	xmlns:cfg="http://metalx.org/Pc/Pci/Configuration"
	xmlns:dsk="http://metalx.org/Pc/Floppy/Ports"
	xmlns:fcmd="http://metalx.org/Pc/Floppy/Commands"
	xmlns:fdr="http://metalx.org/Pc/Floppy/DataRate"
	xmlns:fdo="http://metalx.org/Pc/Floppy/DigitalOutput"
	xmlns:fst="http://metalx.org/Pc/Floppy/Status"
	xmlns:kbd="http://metalx.org/Pc/Keyboard">

	<cls:field name="Device" type="http://metalx.org/Pci/PciDevice" offset="0"/>
	<cls:field name="Port" type="http://metalx.org/Byte" offset="4"/>

	<cls:method name="GetBlockCount" type="http://metalx.org/Integer">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddress/>
		
		<!--Select Drive-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:DriveAndHead/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ShiftRegisterByImmediateFunction8/>
		<shift:ShiftALRegisterLeft/>
		<byte>4</byte>

		<cpu:OrALWithImmediate/>
		<binary>11100000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:DriveAndHead/>

		<!--Wait For Drive Select-->
		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<!--Disable DMA-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Features/>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Features/>

		<!--Enable IRQs-->
		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<!--Set Byte Count 0-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount0/>

		<cpu:CopyImmediateToAL/>
		<hex>08</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount0/>

		<!--Set Byte Count 1-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount1/>

		<cpu:CopyImmediateToAL/>
		<hex>00</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount1/>

		<!--Send ATAPI Packet Command-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Command/>

		<cpu:CopyImmediateToAL/>
		<cmd:Packet/>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Command/>

		<!--Wait While Busy-->
		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>

		<!--Send ATAPI Packet-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Data/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0025</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Data/>

		<!--Wait While Busy-->
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>

		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<!--Read Block Count-->
		<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>

		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>16</byte>

		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<cpu:IncrementAX/>

		<cpu:PushAXToStack/>

		<!--Read Block Size-->
		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>16</byte>

		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<cpu:PullAXFromStack/>

		<int:CreateObject/>
		
		<cpu:ReturnToNearCaller/>

		<label id="sleep"/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<cpu:ReturnToNearCaller/>

		<label id="wait"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileBusy"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:Busy/>

		<cpu:BranchToRelative8IfNotZero/>
		<addressOf ref="whileBusy" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>
		
		<label id="poll"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileEmpty"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:DataRequest/>

		<cpu:BranchToRelative8IfZero/>
		<addressOf ref="whileEmpty" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetBlockLength" type="http://metalx.org/Integer">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddress/>

		<!--Select Drive-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:DriveAndHead/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ShiftRegisterByImmediateFunction8/>
		<shift:ShiftALRegisterLeft/>
		<byte>4</byte>

		<cpu:OrALWithImmediate/>
		<binary>11100000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:DriveAndHead/>

		<!--Wait For Drive Select-->
		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<!--Disable DMA-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Features/>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Features/>

		<!--Enable IRQs-->
		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<!--Set Byte Count 0-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount0/>

		<cpu:CopyImmediateToAL/>
		<hex>08</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount0/>

		<!--Set Byte Count 1-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount1/>

		<cpu:CopyImmediateToAL/>
		<hex>00</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount1/>

		<!--Send ATAPI Packet Command-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Command/>

		<cpu:CopyImmediateToAL/>
		<cmd:Packet/>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Command/>

		<!--Wait While Busy-->
		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>

		<!--Send ATAPI Packet-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Data/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0025</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Data/>

		<!--Wait While Busy-->
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>

		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<!--Read Block Count-->
		<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>

		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>16</byte>

		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<cpu:IncrementAX/>

		<!--Read Block Size-->
		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>16</byte>

		<cpu:Operand16/>
		<cpu:ReadFromDXPortToAX/>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>8</byte>

		<int:CreateObject/>

		<cpu:ReturnToNearCaller/>

		<label id="sleep"/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<cpu:ReturnToNearCaller/>

		<label id="wait"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileBusy"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:Busy/>

		<cpu:BranchToRelative8IfNotZero/>
		<addressOf ref="whileBusy" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>

		<label id="poll"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileEmpty"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:DataRequest/>

		<cpu:BranchToRelative8IfZero/>
		<addressOf ref="whileEmpty" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>
	</cls:method>
	
	<cls:method name="Open" type="http://metalx.org/Storage/CdDrive">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddress/>

		<!--Select Drive-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:DriveAndHead/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ShiftRegisterByImmediateFunction8/>
		<shift:ShiftALRegisterLeft/>
		<byte>4</byte>

		<cpu:OrALWithImmediate/>
		<binary>11100000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:DriveAndHead/>

		<!--Wait For Drive Select-->
		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<!--Disable DMA-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Features/>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Features/>

		<!--Enable IRQs-->
		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<!--Set Byte Count 0-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount0/>

		<cpu:CopyImmediateToAL/>
		<hex>00</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount0/>

		<!--Set Byte Count 1-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount1/>

		<cpu:CopyImmediateToAL/>
		<hex>00</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount1/>

		<!--Send ATAPI Packet Command-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Command/>

		<cpu:CopyImmediateToAL/>
		<cmd:Packet/>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Command/>
		
		<!--Wait While Busy-->
		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>

		<!--Send ATAPI Packet-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Data/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>001B</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0002</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Data/>

		<!--Wait While Busy-->
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>

		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<!--Read Error-->
		<!--<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Error/>

		<cpu:CopyImmediateToAH/>
		<byte>0</byte>
		
		<cpu:ReadFromDXPortToAL/>

		<int:CreateObject/>-->

		<cpu:ReturnToNearCaller/>

		<label id="sleep"/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<cpu:ReturnToNearCaller/>
		
		<label id="wait"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileBusy"/>
		
		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:Busy/>

		<cpu:BranchToRelative8IfNotZero/>
		<addressOf ref="whileBusy" type="Relative8"/>
		
		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>
		
		<label id="poll"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileEmpty"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:DataRequest/>

		<cpu:BranchToRelative8IfZero/>
		<addressOf ref="whileEmpty" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="Close" type="http://metalx.org/Storage/CdDrive">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddress/>

		<!--Select Drive-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:DriveAndHead/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ShiftRegisterByImmediateFunction8/>
		<shift:ShiftALRegisterLeft/>
		<byte>4</byte>

		<cpu:OrALWithImmediate/>
		<binary>11100000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:DriveAndHead/>

		<!--Wait For Drive Select-->
		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<!--Disable DMA-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Features/>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Features/>

		<!--Enable IRQs-->
		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<!--Set Byte Count 0-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount0/>

		<cpu:CopyImmediateToAL/>
		<hex>00</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount0/>

		<!--Set Byte Count 1-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount1/>

		<cpu:CopyImmediateToAL/>
		<hex>00</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount1/>

		<!--Send ATAPI Packet Command-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Command/>

		<cpu:CopyImmediateToAL/>
		<cmd:Packet/>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Command/>

		<!--Wait While Busy-->
		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>

		<!--Send ATAPI Packet-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Data/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>001B</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0003</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Data/>

		<!--Wait While Busy-->
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>

		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<!--Read Error-->
		<!--<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Error/>

		<cpu:CopyImmediateToAH/>
		<byte>0</byte>

		<cpu:ReadFromDXPortToAL/>

		<int:CreateObject/>-->

		<cpu:ReturnToNearCaller/>

		<label id="sleep"/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<cpu:ReturnToNearCaller/>

		<label id="wait"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileBusy"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:Busy/>

		<cpu:BranchToRelative8IfNotZero/>
		<addressOf ref="whileBusy" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>

		<label id="poll"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileEmpty"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:DataRequest/>

		<cpu:BranchToRelative8IfZero/>
		<addressOf ref="whileEmpty" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetModel" type="http://metalx.org/String">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddress/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cd:GetModelNumber/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetSerialNumber" type="http://metalx.org/String">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddress/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cd:GetSerialNumber/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="FirstBlock" type="http://metalx.org/Storage/CdDriveBlockIterator">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:LogicFunction/>
		<logic:PushSIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:LogicFunction/>
		<logic:PushSIAddress/>

		<cpu:CopyImmediateToDI/>
		<addressOf ref="className" type="Absolute32"/>

		<sys:GetCatalog/>

		<cat:FindType/>

		<!--<cpu:PushSIToStack/>-->

		<cpu:CopyRegisterToOperand/>
		<op:SI-BXRegister/>

		<mm:CheckOut length="9"/>

		<cpu:CopyImmediateToOperandFunction/>
		<imm:CopyImmediateToDIAddress/>
		<int>0</int>

		<cpu:PullAXFromStack/>

		<cpu:CopyRegisterToOperand/>
		<op:AX-DIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:PullAXFromStack/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-DIAddressPlusImmediate8/>
		<byte>8</byte>

		<obj:Create/>

		<cpu:ReturnToNearCaller/>

		<var:string id="className">http://metalx.org/Ahci/AhciCdDriveBlockIterator</var:string>
	</cls:method>

	<cls:method name="ToString" type="http://metalx.org/String">
		<cpu:CopyImmediateToDI/>
		<addressOf ref="deviceName" type="Absolute32"/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>

		<var:string id="deviceName">CD-ROM Drive</var:string>
		
		<!--<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddress/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cd:GetModelNumber/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>-->
	</cls:method>

	<cls:method name="GetClass" type="http://metalx.org/Class">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetType/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<clsf:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>
</cls:class>